package com.morty.user.controller;

import cn.hutool.core.bean.BeanUtil;
import com.morty.user.entity.User;
import com.morty.user.entity.UserLock;
import com.morty.user.service.UserService;
import com.morty.user.vo.UserLockVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.morty.user.vo.UserInfoVo;

import javax.annotation.Resource;


@RestController
@RequestMapping("/management/user")
public class UserController implements UserControllerApi{

    @Resource
    private UserService userService;

    @Override
    public UserInfoVo getUserById(String userId) {
        UserInfoVo userVo = new UserInfoVo();
        User user= userService.getUserById(userId);
        userVo = BeanUtil.toBean(user,UserInfoVo.class);
        return userVo;
    }

    @Override
    public UserLockVo getUserLockById(String userId){
        UserLockVo userVo = new UserLockVo();
        UserLock user= userService.getUserLockById(userId);
        userVo = BeanUtil.toBean(user,UserLockVo.class);
        return userVo;
    }

    @Override
    public int insertUser(UserInfoVo userInfoVo) {
        User user= new User();
        user = BeanUtil.toBean(userInfoVo,User.class);
        return userService.insertUser(user);
    }

    @Override
    public int updateUser(UserInfoVo userInfoVo) {
        User user= new User();
        user = BeanUtil.toBean(userInfoVo,User.class);
        return userService.updateUser(user);
    }

    @Override
    public int updateUserLock(UserLockVo userLockVo){
        UserLock user= new UserLock();
        user = BeanUtil.toBean(userLockVo,UserLock.class);
        return userService.updateUserLock(user);
    }
}
